|
|
|
|
|
|
|
When you enlarge an image, you face the problem described earlier in which you do not have enough data to give values to all the pixels in the result. You can solve this problem using bilinear interpolation, also described earlier. |
|
|
|
|
|
|
|
|
Example program Stretch2, shown in Figure 7.14, uses bilinear interpolation to enlarge an image. Compare the results to those of program Stretch shown in Figure 7.12. Program Stretch uses PaintPicture to enlarge the image. The images produced by program Stretch2 are less blocky, though they appear fuzzier and they take much longer to create. Because of its greater speed, PaintPicture is still useful when speed is more important than image quality. |
|
|
|
|
|
|
|
|
Program Stretch2 uses the EnlargePicture subroutine shown in the following code to enlarge its image. EnlargePicture takes as parameters the minimum X and Y coordinates for the input and output areas and saves them in global variables that the MapPixel routine can access later. It also takes parameters giving the widths and heights of the input and output areas. It uses those values to calculate the scale by which the image will be stretched in the X and Y directions. |
|
|
|
|
|
|
|
|
EnlargePicture subtracts 1 from the input area's width and height so that pixels will map inside the original image. If it used the entire input area, pixels along the right and bottom edges of the result would not map inside the original image, so their values would not be defined. |
|
|
|
|
|
|
|
|
After setting these global values, EnlargePicture calls the TransformImage routine described in the previous section. TransformImage calls the MapPixel subroutine, which uses the values saved by EnlargePicture. |
|
|
|
|
|
|
|
|
Figure 7.14
Program Stretch2 uses bilinear
interpolation to enlarge an image. |
|
|
|
|
|